package com.orilore.gb.util;

import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class ConnFactory {
	
	
	public static Connection  getConnection() throws Exception{
		
//		  
//		   DocumentBuilderFactory  dbf = DocumentBuilderFactory.newInstance();
//		   
//		   
//		   DocumentBuilder  db = dbf.newDocumentBuilder();
//		   
//			String classpath = System.getProperty("java.class.path");
//			
//            File file = new File(classpath+"/Config.xml");
//			
//			Document  document = db.parse(file);
//			
//			NodeList  alist =   document.getElementsByTagName("url");
//			
//			Element  a = (Element) alist.item(0);
//			
//			String url = a.getFirstChild().getNodeValue();
//			
//			
//	        NodeList  blist =   document.getElementsByTagName("driver");
//			
//			Element  b = (Element) blist.item(0);
//			
//			String driver = b.getFirstChild().getNodeValue();
//			
//			
//		     NodeList  clist =   document.getElementsByTagName("username");
//				
//				Element  c = (Element) clist.item(0);
//				
//				String username = c.getFirstChild().getNodeValue();
//				
//				
//			     NodeList  dlist =   document.getElementsByTagName("password");
//					
//			     Element  d = (Element) dlist.item(0);
//					
//			     String password = d.getFirstChild().getNodeValue();
//			
//			
			     Class.forName("com.mysql.jdbc.Driver");
			
		   
			     Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/myproject","root","olcpolcp");
			     
			     
			     
			     
		    return conn;
		
		
		
		
		
	}
	
	public static void closeConnection(Connection conn) throws Exception {
		
		
		   conn.close();
		
		
	}
	
	
	

}
